package siga.visao_academico;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import siga.banco.conexao;
import siga.pacotao.contadorData;
import siga.visao_busca.buscaPlanoPagamento;
import siga.visao_busca.buscaTurma;
import siga.visao_busca.buscaVer;
import siga.visao.index;
import siga.visao.verErros;

public class GestaoMatricular_insMatricula extends javax.swing.JDialog {
    public boolean matricula=false;
    public GestaoMatricular_insMatricula(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jtfCodPessoa = new javax.swing.JTextField();
        jtfDesPessoa = new javax.swing.JTextField();
        jtfCodTurma = new javax.swing.JTextField();
        jtfFase = new javax.swing.JTextField();
        jbBusca = new javax.swing.JButton();
        jbBusca1 = new javax.swing.JButton();
        jbBusca2 = new javax.swing.JButton();
        jtfCodPlano = new javax.swing.JTextField();
        jtfDesPlano = new javax.swing.JTextField();
        jtfDataPlano = new javax.swing.JFormattedTextField();
        jtfQtdParc = new javax.swing.JTextField();
        jtfValor = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jtfAno = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jtfSemestre = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jtfEnlace = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Matriculando");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Acadêmico");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Turma");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Fase/Série/Módulo");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText("Plano de Pagamento");
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText("Dt. de Início");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText("Qtd. de Parcelas");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel8.setText("Valor");
        jLabel8.setName("jLabel8"); // NOI18N

        jtfCodPessoa.setEditable(false);
        jtfCodPessoa.setName("jtfCodPessoa"); // NOI18N

        jtfDesPessoa.setEditable(false);
        jtfDesPessoa.setName("jtfDesPessoa"); // NOI18N

        jtfCodTurma.setEditable(false);
        jtfCodTurma.setName("jtfCodTurma"); // NOI18N

        jtfFase.setEditable(false);
        jtfFase.setName("jtfFase"); // NOI18N

        jbBusca.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBusca.setText("Buscar");
        jbBusca.setEnabled(false);
        jbBusca.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbBusca.setName("jbBusca"); // NOI18N
        jbBusca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscaActionPerformed(evt);
            }
        });

        jbBusca1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBusca1.setText("Buscar");
        jbBusca1.setEnabled(false);
        jbBusca1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbBusca1.setName("jbBusca1"); // NOI18N
        jbBusca1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBusca1ActionPerformed(evt);
            }
        });

        jbBusca2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jbBusca2.setText("Buscar");
        jbBusca2.setEnabled(false);
        jbBusca2.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbBusca2.setName("jbBusca2"); // NOI18N
        jbBusca2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBusca2ActionPerformed(evt);
            }
        });

        jtfCodPlano.setEditable(false);
        jtfCodPlano.setName("jtfCodPlano"); // NOI18N

        jtfDesPlano.setEditable(false);
        jtfDesPlano.setName("jtfDesPlano"); // NOI18N

        jtfDataPlano.setEditable(false);
        try {
            jtfDataPlano.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jtfDataPlano.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfDataPlano.setName("jtfDataPlano"); // NOI18N

        jtfQtdParc.setEditable(false);
        jtfQtdParc.setName("jtfQtdParc"); // NOI18N

        jtfValor.setEditable(false);
        jtfValor.setName("jtfValor"); // NOI18N

        jButton1.setText("Cancelar");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Salvar");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Novo");
        jButton3.setEnabled(false);
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel7.setText("Ano");
        jLabel7.setName("jLabel7"); // NOI18N

        jtfAno.setEditable(false);
        jtfAno.setName("jtfAno"); // NOI18N

        jLabel9.setText("Semestre");
        jLabel9.setName("jLabel9"); // NOI18N

        jtfSemestre.setEditable(false);
        jtfSemestre.setName("jtfSemestre"); // NOI18N

        jLabel10.setText("Ensalamento");
        jLabel10.setName("jLabel10"); // NOI18N

        jtfEnlace.setEditable(false);
        jtfEnlace.setName("jtfEnlace"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtfCodPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDesPessoa, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBusca))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jtfCodTurma, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBusca1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfFase, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jtfAno, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfSemestre, 0, 0, Short.MAX_VALUE)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfEnlace)
                            .addComponent(jLabel10)))
                    .addComponent(jLabel4)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jtfCodPlano, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfDesPlano, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBusca2))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfDataPlano, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfQtdParc)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCodPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfDesPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbBusca))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfCodTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbBusca1)
                            .addComponent(jtfAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfFase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtfEnlace, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jLabel7)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfCodPlano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfDesPlano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbBusca2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfDataPlano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfQtdParc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        gerenciaCampos();
        LimpaCampos();
        if(!index.LRpessoa.get(0).equals("")){
            jtfCodPessoa.setText(index.LRpessoa.get(0).toString());
            jtfDesPessoa.setText(index.LRpessoa.get(1).toString());
        }
        index.LRpessoa.add(0, "");
        index.LRpessoa.add(1, "");
        
    }//GEN-LAST:event_formWindowOpened

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        matricula=true;
    }//GEN-LAST:event_formWindowClosed

    private void jbBuscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscaActionPerformed
        buscaVer.setTipo("Academico");
        buscaVer bv = new buscaVer(null,true);
        bv.setLocation((index.tela.width-bv.getWidth())/2, (index.tela.height-bv.getHeight())/2);
        bv.setVisible(true);
        if(buscaVer.isConfirmaBusca()){
            jtfCodPessoa.setText(index.LRpessoa.get(0).toString());
            jtfDesPessoa.setText(index.LRpessoa.get(1).toString());
        }
        index.LRpessoa.add(0, "");
        index.LRpessoa.add(1, "");
    }//GEN-LAST:event_jbBuscaActionPerformed

    private void jbBusca1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBusca1ActionPerformed
        buscaTurma bt = new buscaTurma(null,true);
        bt.setLocation((index.tela.width-bt.getWidth())/2, (index.tela.height-bt.getHeight())/2);
        bt.setVisible(true);
        if(buscaTurma.isConfirmaTurma()){
            try {
                jtfCodTurma.setText(index.LRturma.get(0).toString());
                jtfFase.setText(index.LRfase.get(0).toString());
                conexao.Query("select * from grade_turma where codigo=\"" + index.LRturma.get(0) + "\" and cod_emp=" + index.cod_emp);
                conexao.rs.next();
                jtfEnlace.setText(conexao.rs.getString("enlace"));
                jtfSemestre.setText(conexao.rs.getString("semestre"));
                jtfAno.setText(conexao.rs.getString("ano"));
            } catch (SQLException ex) {
                verErros.setErro(ex.getMessage());
            }
        }
        index.LRturma.add(0, "");
        index.LRturma.add(1, "");
    }//GEN-LAST:event_jbBusca1ActionPerformed

    private void jbBusca2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBusca2ActionPerformed
        buscaPlanoPagamento bpp = new buscaPlanoPagamento(null,true);
        bpp.setLocation((index.tela.width-bpp.getWidth())/2, (index.tela.height-bpp.getHeight())/2);
        bpp.setVisible(true);
        if(!index.LRplanopag.get(0).equals("")){
            try {
                conexao.Query("select * from fin_plano_pagamento where cod_emp=" + index.cod_emp + " and codigo=" + index.LRplanopag.get(0));
                conexao.rs.next();
                jtfCodPlano.setText(index.LRplanopag.get(0).toString());
                jtfDesPlano.setText(index.LRplanopag.get(1).toString());
                jtfQtdParc.setText(conexao.rs.getString("nr_parcela"));
                jtfValor.setText(index.ftbr.format(conexao.rs.getDouble("valor")));
                String dtTabela1 = new SimpleDateFormat("dd/MM/yyyy").format(conexao.rs.getDate("dt_inicio"));
                jtfDataPlano.setText(dtTabela1);
            } catch (SQLException ex) {
                verErros.setErro(ex.getMessage());
            }
        }
        index.LRplanopag.add(0, "");
        index.LRplanopag.add(1, "");
    }//GEN-LAST:event_jbBusca2ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        if(!jtfDesPessoa.getText().equals("")){
            if(!jtfFase.getText().equals("")){
                try {
                    conexao.Query("select gc.*, gd.cod_prof_t, gd.cod_prof_a from grade_curricular gc " +
                            " inner join grade_disciplina gd on gd.codigo=gc.cod_disciplina and gd.cod_curso=gc.cod_curso and gd.cod_emp=gc.cod_emp" +
                            " where gc.cod_emp=" + index.cod_emp + " and gc.cod_curso=" + jtfCodTurma.getText().substring(0, 3) + " and gc.cod_fase=" + jtfFase.getText() + " order by gc.cod_disciplina");
                    String[] inserir=new String[50];
                    int cont = 0;
                    while (conexao.rs.next()) {
                        inserir[cont] ="replace into diario(cod_pessoa,cod_emp,cod_fase,ano,cod_disciplina,cod_matricula,cod_curso,cod_prof_t, cod_prof_a,cod_situacao,semestre,dt_cancelamento)" +
                                " values("+jtfCodPessoa.getText()+","+index.cod_emp+","+jtfFase.getText()+","+jtfAno.getText()+","+conexao.rs.getString("cod_disciplina")+",\""+jtfCodTurma.getText()+"\","+jtfCodTurma.getText().substring(0,3)+","+conexao.rs.getString("cod_prof_t")+","+conexao.rs.getString("cod_prof_a")+",1,\""+jtfAno.getText()+"/"+jtfSemestre.getText()+"\",now());";
                        cont++;
                    }
                    for(int i=0;i<cont;i++){
                        conexao.Inserir(inserir[i]);
                    }
                    conexao.Inserir("update pessoas set tipo=\"Academico\" where cod_emp="+index.cod_emp+" and codigo="+jtfCodPessoa.getText());
                } catch (SQLException ex) {
                    verErros.setErro(ex.getMessage());
                }
                if(!jtfDesPlano.getText().equals("")){
                    try {
                        conexao.Query("select * from fin_plano_pagamento where cod_emp=" + index.cod_emp + " and codigo=" + jtfCodPlano.getText());
                        conexao.rs.next();
                        String data = conexao.rs.getString("dt_inicio");
                        contadorData.setDataSomaMes(data, "US");
                        int cont = conexao.rs.getInt("nr_parcela");
                        String codigo = conexao.rs.getString("codigo");
                        String valor = conexao.rs.getString("valor");
                        for(int i=1; i<=cont;i++){
                            conexao.Inserir("insert into fin_contas_mov_r(cod_emp,cod_plano_contas,cod_centro_custos, cod_plano_pagamento,cod_matricula,cod_fase,cod_pessoa,parcela,dt_emissao,dt_vencimento,valor_bruto,status) " +
                                    "values("+index.cod_emp+",74,1,"+codigo+",\""+jtfCodTurma.getText()+"\","+jtfFase.getText()+","+jtfCodPessoa.getText()+","+i+",now(),\""+data+" 00:00:00\","+valor+",\"A Receber\")");
                            data = contadorData.getDataSomaMes();
                        }
                    } catch (SQLException ex) {
                        verErros.setErro(ex.getMessage());
                    }
                }
                gerenciaCampos();
                LimpaCampos();
                jButton3.setEnabled(true);
                jButton2.setEnabled(false);
            }else{
                JOptionPane.showMessageDialog(null, "Campo Turma é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                jtfCodTurma.requestFocus();
            }
        }else{
           JOptionPane.showMessageDialog(null, "Campo Acadêmico é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
           jtfCodPessoa.requestFocus();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        matricula=true;
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        gerenciaCampos();
        LimpaCampos();
        jButton3.setEnabled(false);
        jButton2.setEnabled(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void gerenciaCampos(){
        jtfCodPlano.setEditable(!jtfCodPessoa.isEditable());
        jtfCodTurma.setEditable(!jtfCodPessoa.isEditable());
        jtfCodPessoa.setEditable(!jtfCodPessoa.isEditable());
        jbBusca1.setEnabled(!jbBusca.isEnabled());
        jbBusca2.setEnabled(!jbBusca.isEnabled());
        jbBusca.setEnabled(!jbBusca.isEnabled());
    }

    private void LimpaCampos(){
        jtfCodPessoa.setText("");
        jtfCodPlano.setText("");
        jtfDataPlano.setText("  /  /    ");
        jtfDesPessoa.setText("");
        jtfDesPlano.setText("");
        jtfFase.setText("");
        jtfQtdParc.setText("");
        jtfValor.setText("");
        jtfCodTurma.setText("");
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JButton jbBusca;
    private javax.swing.JButton jbBusca1;
    private javax.swing.JButton jbBusca2;
    private javax.swing.JTextField jtfAno;
    private javax.swing.JTextField jtfCodPessoa;
    private javax.swing.JTextField jtfCodPlano;
    private javax.swing.JTextField jtfCodTurma;
    private javax.swing.JFormattedTextField jtfDataPlano;
    private javax.swing.JTextField jtfDesPessoa;
    private javax.swing.JTextField jtfDesPlano;
    private javax.swing.JTextField jtfEnlace;
    private javax.swing.JTextField jtfFase;
    private javax.swing.JTextField jtfQtdParc;
    private javax.swing.JTextField jtfSemestre;
    private javax.swing.JTextField jtfValor;
    // End of variables declaration//GEN-END:variables

}
